#include <list>
#include <string>
#include <iostream>

// 基类
class Subject;

class Observer {
public:
    Observer(std::string name, Subject* sub) {
        this->name = name;
        this->sub = sub;
    }
    virtual void Update(){}

protected:
    std::string name;
    Subject* sub;
};

class Subject {
public:
    virtual void Attach(Observer* observer){}
    virtual void Detach(Observer* observer){}
    virtual void Notify(){}

    std::string SubjectState;
};


// 派生类
class StockObserver : public Observer {
public:
    StockObserver(std::string name, Subject* sub) : Observer(name, sub) {}
    void Update() override {
        std::cout << "看股票的同事收到消息："<< sub->SubjectState << std::endl;
    }
};

class NBAObserver : public Observer {
public:
    NBAObserver(std::string name, Subject* sub) : Observer(name, sub) {}
    void Update() override {
        std::cout << "看NBA的同事收到消息："<< sub->SubjectState << std::endl;
    }
};


class Secretary : public Subject {
public:
    // 同事列表
    std::list<Observer*> observers;

public:
    // 增加
    void Attach(Observer* observer) {
        this->observers.push_back(observer);
    }

    // 减少
    void Detach(Observer* observer) {
        this->observers.remove(observer);
    }

    // 通知
    void Notify() {
        for (auto o : observers) {
            o->Update();
        }
    }
};